import json
from core.base_tornado_request_handler import BaseTornadoRequestHandler
from db import LogsDB

class ApiLogHandler(BaseTornadoRequestHandler):
  async def get(self, action):
    if action == "list":
      await self.get_list()
      
  
  async def post(self, action):
    if action == "clear":
      await self.clear_role()

  async def get_list(self):
    log_list = await LogsDB.all()
    self.return_json({"list": [log.to_dict() for log in log_list]})
  
  async def clear_role(self):
    num = await LogsDB.all().delete()
    self.return_json({"num": num})